test_pgm       := $(notdir $(TEST_DIR))/unit-test
test_src       := $(patsubst $(TEST_DIR)/%,%,$(wildcard $(TEST_DIR)/$(if $(TEST_MODULE),$(TEST_MODULE),*)/*.cxx))
test_objs      := $(call source-to-object,$(test_src))
dependent_libs := $(modules)

test_programs += $(test_pgm)
sources  += $(test_src)

vpath %.cxx $(TEST_DIR)

GMOCK_DIR := $(TEST_DIR)/3rd-party/gmock-1.6.0

$(test_pgm): CPPFLAGS += $(addprefix -I ,$(GMOCK_DIR)/include $(GMOCK_DIR)/gtest/include)
$(test_pgm): LDLIBS += $(GMOCK_DIR)/make/gmock_main.a -lpthread

$(eval $(call make-program,$(test_pgm),$(test_objs),$(dependent_libs)))

.PHONY: unit-test
unit-test: $(test_pgm)
	$(QUIET)$(test_pgm)

tests += unit-test
